package com.minelx.scriptbuilder.parse.matcher;

import com.minelx.scriptbuilder.parse.parser.CommonValueMatcher.Affection;
import com.minelx.sequence.IStringScanner;
import com.minelx.sequence.ReturnMatcher;

public class DotAttributeMatcher implements ReturnMatcher<Affection, Affection> {
	@Override
	public boolean isMatch(Affection bundle) {
		IStringScanner copy = bundle.getScanner().copy();
		if (!copy.exists(".")) {
			return false;
		}
		copy.nextChar(); // '.'
		if (!copy.existsIf(Character::isAlphabetic)) {
			return false;
		}
		copy.nextPage(); // attributeName
		return true;
	}

	@Override
	public Affection onMatched(Affection affection) {
		affection.getScanner().nextChar();
		String name = affection.getScanner().nextPage();
		affection.effectedBy(affection.belongs().dot(name));
		return affection;
	}
}
